package cn.dhnep.demo.service.impl;

import cn.dhnep.demo.mapper.OrderItemMapper;
import cn.dhnep.demo.mapper.OrderMapper;
import cn.dhnep.demo.pojo.Order;
import cn.dhnep.demo.pojo.frontvo.OrderAddCount;
import cn.dhnep.demo.pojo.frontvo.OrderVo;
import cn.dhnep.demo.service.OrderService;
import cn.dhnep.demo.util.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dhn
 * @since 2021-08-18
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderItemMapper orderItemMapper;


    @Override
    public List<Order> selectPageList(Page page) {
        return orderMapper.selectPageList(page);
    }

    @Override
    public Integer selectPageCount(Page page) {
        return orderMapper.selectPageCount(page);
    }

    @Override
    public Order idqueryOrder(Integer id) {
        return orderMapper.idqueryOrder(id);
    }

    @Override
    public int updateorder(Order order) {
        return orderMapper.updateorder(order);
    }

    @Override
    public List<OrderAddCount> getYesterdayOrder(String name) {
        return orderMapper.getYesterdayOrder(name);
    }

    @Override
    public List<OrderVo> horsemanEvenDayEarnings() {
        List<OrderVo> orderVos = baseMapper.horsemanEvenDayEarnings();
        orderVos.forEach(orderVo -> orderVo.setOrderCount(baseMapper.horsemanYesterdayCount(orderVo.getHorsemanName()))
                .setOrderAddCounts(baseMapper.getYesterdayOrder(orderVo.getHorsemanName()))
                .setOrderItemVos(orderItemMapper.getYesterdayOrderWeightAndMoneyAndProductType(orderVo.getHorsemanName())));
        return orderVos;
    }
}
